﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace OpenExpressApp.Module.View
{
    /// <summary>
    /// 视图行为的基类
    /// </summary>
    public abstract class ViewBehavior : IViewBehavior
    {
        private ObjectView _view;

        /// <summary>
        /// 是否已经绑定到某个视图
        /// </summary>
        public bool IsAttached { get; private set; }

        #region IViewBehavior Members

        public ObjectView View
        {
            get
            {
                return _view;
            }
            set
            {
                if (!IsAttached)
                {
                    this._view = value;
                }
            }
        }

        public void Attach()
        {
            Debug.Assert(null != _view, "ViewBehavior必须绑定到View上");
            IsAttached = true;
            OnAttach();
        }

        #endregion

        protected abstract void OnAttach();
    }
}
